#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>

using namespace std;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindowClass)
{
    ui->setupUi(this);
    timer = new QTimer(this);
   
    QActionGroup *group = new QActionGroup(ui->mainToolBar);
    this->x = new QAction("X", group);
    this->x->setCheckable(true);
    this->y = new QAction("Y", group);
    this->y->setCheckable(true);
    this->z = new QAction("Z", group);
    this->z->setCheckable(true);
    this->parar = new QAction("Parar", group);
    this->parar->setCheckable(true);
    
    //this->boton = new QAction("boton", group);

	QAction *boton = ui->mainToolBar->addAction("boton");
    ui->mainToolBar->addAction(this->x);
    ui->mainToolBar->addAction(this->y);
    ui->mainToolBar->addAction(this->z);
    ui->mainToolBar->addAction(this->parar);


    connect(boton, SIGNAL(triggered()), this, SLOT(graficar()));
    connect(this->x, SIGNAL(triggered()), this, SLOT(graficar()));
  	connect(this->parar, SIGNAL(triggered()), this, SLOT(pararTimer()));

	connect(ui->pushEmpezar, SIGNAL(clicked()), this, SLOT(graficar()));
	
	
	connect(ui->pushParar, SIGNAL(clicked()), this, SLOT(pararTimer()));

    buffer.setSamplingRate(0.01);		//0.04 para 25 ms	
	buffer.initialize();

	
	plot = new DataPlot(this,&(buffer.algoritmosY));	
    setCentralWidget(plot);
    plot->setTimerInterval(-1);
}

void MainWindow::pararTimer()
{
    plot->setTimerInterval(-1);
    buffer.stopPort();		
}

void MainWindow::graficar()
{
//    ui->statusBar->showMessage("Calibrando... por favor espere...", 3200);
     

    buffer.start();						//empieza a recibir los datos

  	plot->setTimerInterval(5);			//refresco en ms
                
}

MainWindow::~MainWindow()
{
    delete ui;
}
